var vueApp = new Vue({
  el: '#app',
  data: function () {
    return {
      
        currentPageNbr: config.currentPageNbr,
        pageSizes: config.pageSizes,
        pageSize: 10,
        totalRecords: 0,       
        data: [],
        dialogFlag: false,
        name:'',
      };
  },
  mounted: function () {
    this.initData();

  },
  methods: {
  add:function(){
		  this.name= "";		
		  this.dialogFlag=true;

   },	  
   doAdd:function(){
	   var that = this;
	   var reqData = {
			   name: this.name			
			  };
	   tools.ajaxRequestAsyncEx("pub/attach/addname",reqData,function(data){
			  console.log(data);
     	  if (data.respCode != 0) {
     		  that.showError(data.respDesc);
     	  }else{
     		  that.$message({
		        	showClose: true,
		            type: 'success',
		            message: '添加标签成功!'
		          });		        
		          this.dialogFlag=false;  
     	  }		        	  
       });
	  
   },
   cancel:function(){
	   this.dialogFlag=false;  
   },  
   delFile:function(row){
        var that = this;
        console.log(row.file_id);       
		  var postdata = {
			"file_id":row.file_id
		  }
		  var data = tools.ajaxRequestEx("pub/attach/fileDel",postdata);
	      if (data.respCode == "0") {
	    	  this.onSearch(); 
	      }else {
	         this.showError(data.respDesc);     
	         return false;
	      }  	
      
     }, 
     preImg:function(row){
     	if(row.url!="")
     	{
     		var arr= [] ;
     		arr.push(row.url);
     		return arr;
     	}    	
         return arr;
     },
	 onSearch:function(){
	     // console.log(this.datenum);
		 var that = this;   
		 
		 var jsonStr ={ };
		 var postdata = {
		       "jsonStr": JSON.stringify(jsonStr),           
		   "currentPageNbr" : this.currentPageNbr,
		   "pageSize" : this.pageSize
		 };
		
		 tools.ajaxRequestAsyncEx("pub/attach/filelist",postdata, function(data){
		  if (data.respCode == "0") {
		           	  console.log(data.list);
		                 that.data = data.list;
		                 that.totalRecords = data.page.totalRecords;       
		             } else {
		                 that.data = [];
		                 that.totalRecords =0;
		                 that.currentPageNbr=1;
		                 that.showError(data.respDesc);      
		             }
		         });
		
	
	 }, 
    initData:function(){
       var that = this;      
       this.onSearch();       
    },  
   
   
    handleSizeChange:function(pageSize){
        this.pageSize = pageSize;
    },

    handleCurrentChange:function(currentPageNbr){
      this.currentPageNbr = currentPageNbr;
    },

    showError: function(info){
        var i = (info==undefined?"加载数据错误":info);
        this.$alert(i, '系统错误', {
             confirmButtonText: '确定'
        }); 
    },

  },
  watch:{
      currentPageNbr : function() {
          // alert(this.currentPageNbr);
          this.onSearch();
      },
        
      pageSize : function() {
          // alert(this.currentPageNbr);
      	if(this.currentPageNbr==1){
   		 this.onSearch();
   	}else{
   		this.currentPageNbr=1;
   	}
      },
  }
  
})